{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import QuantLib as ql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "settings = ql.Settings.instance()\n",
    "evDate = ql.Date(24, 3, 2023)\n",
    "settings.setEvaluationDate(evDate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "Cal = ql.China()\n",
    "DC360 = ql.Actual360()\n",
    "settlementDays = 0\n",
    "refDate = Cal.advance(evDate, settlementDays, ql.Days, ql.Following, False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "d0 = ql.Date(24, 3, 2023)\n",
    "d1 = ql.Date(24, 4, 2023)\n",
    "d2 = ql.Date(24, 6, 2023)\n",
    "d3 = ql.Date(24, 9, 2023)\n",
    "d4 = ql.Date(24, 12, 2023)\n",
    "d5 = ql.Date(24, 3, 2024)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "V_Date = ql.DateVector([d0, d1, d2, d3, d4, d5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "V_Rate = ql.DoubleVector([0.0128, 0.02399, 0.02473, 0.02548, 0.02606, 0.02678])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeroCurve = ql.ZeroCurve(V_Date, V_Rate, DC360, Cal, ql.Linear(), ql.Simple, ql.Annual)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.435320 % Actual/360 simple compounding\n",
      "0.02435319704868347\n"
     ]
    }
   ],
   "source": [
    "d2M = ql.Date(24, 5, 2023)\n",
    "Rate2M = zeroCurve.zeroRate(d2M, DC360, ql.Simple, ql.Annual)\n",
    "print(Rate2M)\n",
    "print(Rate2M.rate())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9958904441949743\n"
     ]
    }
   ],
   "source": [
    "Df2M = zeroCurve.discount(d2M)\n",
    "print(Df2M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9937198012692894\n"
     ]
    }
   ],
   "source": [
    "Df3M = zeroCurve.discount(d2)\n",
    "print(Df3M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.606527 % Actual/360 simple compounding\n"
     ]
    }
   ],
   "source": [
    "F3M6M = zeroCurve.forwardRate(d2, d3, DC360, ql.Simple, ql.Annual)\n",
    "print(F3M6M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df0 = zeroCurve.discount(d0)\n",
    "df1 = zeroCurve.discount(d1)\n",
    "df2 = zeroCurve.discount(d2)\n",
    "df3 = zeroCurve.discount(d3)\n",
    "df4 = zeroCurve.discount(d4)\n",
    "df5 = zeroCurve.discount(d5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "V_DF = ql.DoubleVector([df0, df1, df2, df3, df4, df5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "discCurve = ql.DiscountCurve(V_Date, V_DF, DC360, Cal, ql.LogLinear())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9958614729749544\n"
     ]
    }
   ],
   "source": [
    "Df2M_1 = discCurve.discount(d2M)\n",
    "print(Df2M_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9937198012692894\n"
     ]
    }
   ],
   "source": [
    "Df3M_1 = discCurve.discount(d2)\n",
    "print(Df3M_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
